#include "user.h"
#include<string>
#include<iostream>
#include <fstream>
using namespace std;

User::User(string loginName, string loginPassword)
{
	this->loginName=loginName;
	this->loginPassword=loginPassword;
}

void User::setLoginName(string loginName){this->loginName=loginName;}

void User::setLoginPassword(string loginPassword){this->loginPassword=loginPassword;}

string User::getLoginName(){return loginName;}

string User::getLoginPassword(){return loginPassword;}

void User::readFromFile(fstream& in)
{
	char temp[10];
	in.read(temp,9);  temp[9]='\0';  loginName=temp;     //假定登录名最多9个字符
	in.read(temp,9);  temp[9]='\0';  loginPassword=temp; //假定登录密码最多9个字符
}

void User::writeToFile(fstream& out) const
{
	out.write(loginName.c_str(),9);
	out.write(loginPassword.c_str(),9);
}

istream& operator>>(istream &istrm,User &user)
{
	cout<<"Please enter login name and password：";
	istrm>>user.loginName>>user.loginPassword;
	return istrm;
}

ostream& operator<<(ostream &ostrm,const User &user) { //重载<<
	ostrm<<"登录名:"<<user.loginName<< "\t"<<"密码:"<<user.loginPassword<<endl;
	return ostrm;
}

bool User::operator>(const User &user)
{

	return false;

}
